package com.example.yuejian.yuejian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.bean.ClubClass;

import java.util.List;

;


public class ClubClassAdapter extends RecyclerView.Adapter<ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public ClubClassAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_club_class, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ClubClass entity = (ClubClass) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.class_name.setText(entity.getName());
        viewHolder.class_intro.setText(entity.getIntro());
        viewHolder.class_star.setRating(entity.getGrade());
        viewHolder.class_price.setText("￥"+entity.getPrice());


    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView class_name;
        TextView class_intro;
        RatingBar class_star;
        TextView class_price;

        public ViewHolder(View itemView) {
            super(itemView);
            class_name = (TextView) itemView.findViewById(R.id.club_class_name);
            class_intro = (TextView) itemView.findViewById(R.id.club_class_intro);
            class_star= (RatingBar) itemView.findViewById(R.id.club_class_star);
            class_price=(TextView)itemView.findViewById(R.id.club_class_price);

        }
    }
}
